<?php

class TopicsController extends AppController {

    var $name = 'Topics';
    function index() {
        $this->Topic->recursive = 0;
        $this->set('topics', $this->paginate());
       
    }
    function toan($meet_id=null)
    {
        $topicID= $this->Topic->find('all',
                array(
                    'conditions'=>array('Topic.meet_id'=>$meet_id)
                )
                );
                $this->set('topicID',$topicID);
    }

    function view($id = null) {
        if (!$id) {
            $this->Session->setFlash(__('Invalid topic', true));
            $this->redirect(array('action' => 'index'));
        }
        $result = $this->Topic->uptotal($id);
        $this->set('result', $result);
        $this->set('topic', $this->Topic->read(null, $id));
         
    }

    function add() {
        if (!empty($this->data)) {
            $this->Topic->create();
            if ($this->Topic->save($this->data)) {
                $this->Session->setFlash(__('The topic has been saved', true));
                $this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash(__('The topic could not be saved. Please, try again.', true));
            }
        }
        $meets = $this->Topic->Meet->find('list', array('fields' => 'Meet.meet_name'));
        //$this->set('meets', $meets);
        $this->set(compact('meets'));
    }

    function edit($id = null) {
        if (!$id && empty($this->data)) {
            $this->Session->setFlash(__('Invalid topic', true));
            $this->redirect(array('action' => 'index'));
        }
        if (!empty($this->data)) {
            if ($this->Topic->save($this->data)) {
                $this->Session->setFlash(__('The topic has been saved', true));
                $this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash(__('The topic could not be saved. Please, try again.', true));
            }
        }
        if (empty($this->data)) {
            $this->data = $this->Topic->read(null, $id);
        }
        $meets = $this->Topic->Meet->find('list');
        $this->set(compact('meets'));
    }

    function delete($id = null) {
        if (!$id) {
            $this->Session->setFlash(__('Invalid id for topic', true));
            $this->redirect(array('action' => 'index'));
        }
        if ($this->Topic->delete($id)) {
            $this->Session->setFlash(__('Topic deleted', true));
            $this->redirect(array('action' => 'index'));
        }
        $this->Session->setFlash(__('Topic was not deleted', true));
        $this->redirect(array('action' => 'index'));
    }

    function uptotalview($id = null) {

        //$this->Session->setFlash(__('up sucessfull',true));
    }
//    function show ($id=null){
//        if (!$id) {
//            $this->Session->setFlash(__('Invalid topic', true));
//            $this->redirect(array('action' => 'index'));
//        }
//        $result = $this->Topic->uptotal($id);
//        $this->set('result', $result);
//        $this->set('topic', $this->Topic->read(null, $id));
//    }

}
